/* 
 * File:   Model.h
 * Author: artem
 *
 * Created on November 19, 2011, 1:48 PM
 */

#ifndef MODEL_H
#define MODEL_H

#include "GL/opengl.h"

#include "Common.h"
#include "Shader.h"

#include "Resource/Mesh.h"

namespace Render
{
	class Model
	{
	public:
		Model()
		{
			glGenVertexArrays(1, &m_vao);
			glGenBuffers(2, m_vbo);
		}
		
		Model(const char *name)
		{
			glGenVertexArrays(1, &m_vao);
			glGenBuffers(2, m_vbo);
			
			if (Resource::Mesh *mesh = Resource::loadMesh(name))
			{
				if (!setData(mesh))
					LOG_ERROR("Can't load model '%s'\n", name);
				delete mesh;
			}
		}
		
		~Model()
		{
			glDeleteBuffers(2, m_vbo);
			glDeleteVertexArrays(1, &m_vao);
		}
		
		GLuint getHandle() const { return m_vao; }
		
		const Resource::MeshHead& getMesh() const { return m_mesh; }
		
		bool setData(const Resource::Mesh *mesh);
		
	protected:
		Resource::MeshHead m_mesh;
		GLuint m_vao;
		GLuint m_vbo[2];
	};
}

#endif /* MODEL_H */
